<template>
    <div>
        <h1>会员登录</h1>



        <table>
            <tbody>
                <tr>
                    <td>姓名</td>
                    <td>
                        <input type="text" v-model="data.username"  >
                    </td>
                </tr>
                <tr>
                    <td>密码</td>
                    <td>
                        <input type="password" v-model="data.password">
                    </td>
                </tr>
                <tr>
                    <td colspan="2">
                        <input type="button" value="登录" @click="login">
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">

import { ref } from "vue";
import axios from 'axios';
import { useRouter } from "vue-router";

const router = useRouter();
const data = ref({
    username:'',
    password:'',
})

const login=()=>{
    axios.get("https://localhost:7139/api/Member/Login",{params:data.value}).then(res=>{
        if(res.data.id==-1){
            alert('登录名错了')
            return;
        }
        if(res.data.id==-2){
            alert('密码错了')
            return;
        }
        if(res.data.id > 0){
            alert('登录成功')

            router.push({path:'/'})

        }
        else{
            alert("服务器繁忙，稍后再试。。。");
        }
    })
}

</script>

<style scoped>

</style>